<?php

namespace Products;

use Bank\BankUtils;

class LongDeposit extends Deposit {
	const EIGHTEEN_MONTHS = 18;
	const EIGHTEEN_MONTHS_INTERESTRATE = 5.5;
	const TWENTY_FOUR_MONTHS = 24;
	const TWENTY_FOUR_MONTHS_INTERESTRATE = 6;
	const THIRTY_SIX_MONTHS = 36;
	const THIRTY_SIX_MONTHS_INTERESTRATE = 6.5;
	const SIXTY_MONTHS = 60;
	const SIXTY_MONTHS_INTERESTRATE = 7;
	private $period;
	private $amount;
	private $interestRate;
	public function __construct($period, $amount) {
		$this->setPeriod ( $period );
		$this->setAmount ( $amount );
	}
	public function getPeriod() {
		return $this->period;
	}
	public function setPeriod($period) {
		if ($period == null) {
			throw new BaseException ( "Please enter long deposit period!", BaseException::CODE_1006 );
		}
		if (is_int ( $period ) == false) {
			throw new BaseException ( "Please enter number for long deposit period!", BaseException::CODE_1007 );
		}
		if ($period != 18 || $period != 24 || $period != 36 || $period != 60) {
			throw new BaseException ( "Please enter - 18 months,24 months, 36 months or 60 months for long deposit period!", BaseException::CODE_1008 );
		}
		
		if ($period == self::EIGHTEEN_MONTHS) {
			$this->period = $period;
			$this->setInterestRate ( self::EIGHTEEN_MONTHS_INTERESTRATE );
		}
		if ($period == self::TWENTY_FOUR_MONTHS) {
			$this->period = $period;
			$this->setInterestRate ( self::TWENTY_FOUR_MONTHS_INTERESTRATE );
		}
		if ($period == self::THIRTY_SIX_MONTHS) {
			$this->period = $period;
			$this->setInterestRate ( self::THIRTY_SIX_MONTHS_INTERESTRATE );
		}
		if ($period == self::SIXTY_MONTHS) {
			$this->period = $period;
			$this->setInterestRate ( self::SIXTY_MONTHS_INTERESTRATE );
		}
	}
	public function getAmount() {
		return $this->amount;
	}
	public function setAmount($amount) {
		if ($amount == null) {
			throw new BaseException ( "Please enter long deposit amount!", BaseException::CODE_1009 );
		}
		if (is_double ( $amount ) != true) {
			throw new BaseException ( "Please enter XXX.XX amount!", BaseException::CODE_1010 );
		}
		
		$this->amount = $amount;
	}
	public function getInterestRate() {
		return $this->interestRate;
	}
	public function setInterestRate($interestRate) {
		$this->interestRate = $interestRate;
	}
	public function addInterest() {
		BankUtils::calculateDepositMonthlyPayment ( $this->getPeriod (), $this->getInterestRate () );
	}
	public function showInfo() {
		echo '<p>Long Deposit</p>';
		echo '<p>Long Deposit - period : ' . $this->getPeriod () . '</p>';
		echo '<p>Long Deposit - amount : ' . $this->getAmount () . '</p>';
		echo '<p>Long Deposit - interest rate: ' . $this->getInterestRate () . ' % </p>';
		echo '<p>Long Deposit - monthly payment : ' . BankUtils::calculateDepositMonthlyPayment ( $this->getPeriod (), $this->getInterestRate () * 100 ) . ' BGN</p>';
	}
}
?>